package com.ytsakura.blog.web;


import com.ytsakura.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;


@Controller
public class RankController {

    @Autowired
    private UserService userService;


    @GetMapping("/rank")   //PageableDefault指定分页的默认参数
    public String rank1(@PageableDefault(size = 10,sort = {"mode1"},direction = Sort.Direction.DESC)
                                Pageable pageable, Model model){
        model.addAttribute("page",userService.listUser(pageable));
        model.addAttribute("activeMode",1);
        return "rank";
    }

    @GetMapping("/rank/mode2")   //PageableDefault指定分页的默认参数
    public String rank2(@PageableDefault(size = 10,sort = {"mode2"},direction = Sort.Direction.DESC)
                                Pageable pageable, Model model){
        model.addAttribute("page",userService.listUser(pageable));
        model.addAttribute("activeMode",2);
        return "rank";
    }
    @GetMapping("/rank/mode3")   //PageableDefault指定分页的默认参数
    public String rank3(@PageableDefault(size = 10,sort = {"mode3"},direction = Sort.Direction.DESC)
                                Pageable pageable, Model model){
        model.addAttribute("page",userService.listUser(pageable));
        model.addAttribute("activeMode",3);
        return "rank";
    }
}

